$(document).ready(function() {

	// for image over main menu
	function imageMenuHover(elem, animate){
		var element = $(elem);
		index = $(elem).index();
		var margin_left = 0;
		for(var cont = 0; cont < index; cont ++){
			margin_left = margin_left + $($('#header nav ul li')[cont]).width();
		}
		margin_left = (margin_left + (element.width() / 2) - 5);
		if(animate === false){
			$('#menu_selector_icon').attr('style','margin-left: ' + margin_left + 'px');
			$('#menu_selector_icon').css('visibility', 'visible');
		}
		else{
			$('#menu_selector_icon').stop().animate(
				{
					marginLeft: margin_left + 'px',
				}, 100
			);
		}
	}
	$('#header nav ul li a').hover(function(){
		imageMenuHover($(this).parent());
	});
	var menuIndex = 2;
	var element = $($('#header nav ul li')[menuIndex]);
	setTimeout(function(){ imageMenuHover($(element), false) }, 50);
	
	

	//for main menu
	window.onresize = function(event) {
		if($(document).width() > 800){
			$('#header nav ul').show();
		}
		else{
			$('#header nav ul').hide();
		}
	};
	$('#header nav .button').click(function(){
		$('#header nav ul').slideToggle(100);
	});
	

});